<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script>
    window.onload = () => {
      let obt = document.getElementById('btn')

      obt.onclick = () => {
        const xhr = new XMLHttpRequest()
        console.log(xhr.readyState)   // 0

        xhr.open('GET', 'data/1.txt', true)
        console.log(xhr.readyState)   // 1

        xhr.send()

        xhr.onreadystatechange = () => {
          if (xhr.readyState === 4) {
            if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
              console.log(xhr, 'success')
            } else {
              console.log(xhr, 'failed')
            }
          }
        }

      }
    }
  </script>
</head>
<body>
  <input type="button" id="btn" value="提交" />
</body>
</html>